#!/bin/bash

sudo sed -i 's/^net.ipv4.ip_forward/#_#net.ipv4.ip_forward/' /etc/sysctl.conf
sudo sed -i '1i\net.ipv4.ip_forward = 1' /etc/sysctl.conf

sysctl net.ipv4.ip_forward=1

sudo sed -i 's/^net.ipv6.conf.all.forwarding/#_#net.ipv6.conf.all.forwarding/' /etc/sysctl.conf
sudo sed -i '1i\net.ipv6.conf.all.forwarding = 1' /etc/sysctl.conf

sysctl net.ipv6.conf.all.forwarding=1

sudo sed -i 's/^net.ipv4.conf.all.send_redirects/#_#net.ipv4.conf.all.send_redirects/' /etc/sysctl.conf
sudo sed -i '1i\net.ipv4.conf.all.send_redirects = 0' /etc/sysctl.conf

sudo sed -i 's/^net.ipv4.conf.all.accept_redirects/#_#net.ipv4.conf.all.accept_redirects/' /etc/sysctl.conf
sudo sed -i '1i\net.ipv4.conf.all.accept_redirects = 0' /etc/sysctl.conf

sudo sed -i 's/^net.ipv4.conf.all.accept_source_route/#_#net.ipv4.conf.all.accept_source_route/' /etc/sysctl.conf
sudo sed -i '1i\net.ipv4.conf.all.accept_source_route = 0' /etc/sysctl.conf

for each in /proc/sys/net/ipv4/conf/*
do
echo 0 > $each/accept_redirects
echo 0 > $each/send_redirects
echo 0 > $each/accept_source_route
done

sysctl -p /etc/sysctl.conf

